//
//  PopMenuView.m
//  ScholarsBridge
//
//  Created by ash on 16/12/27.
//  Copyright © 2016年 mingthink. All rights reserved.
//

#import "PopMenuView.h"
@interface PopMenuView ()
@end;
@implementation PopMenuView
-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self showViews];
    }
    return self;
}
- (instancetype)init {
    if (self = [super init]) {
    }
    return self;
}
-(void)showViews{
    UITableView *tbv_main = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
    tbv_main.delegate = self;
    tbv_main.dataSource = self;
    tbv_main.separatorStyle = UITableViewCellSeparatorStyleNone;
    tbv_main.bounces = false;
    [self addSubview:tbv_main];
    self.tbv_main = tbv_main;
    
    _separatorColor = GET_HEX_COLOR(TABLE_SEPARATOR_LIGHTGRAY);
//    self.arr_main = [[NSMutableArray alloc]initWithArray:@[@[@"r_good_03",@"点赞"],@[@"r_collect_small",@"收藏"],@[@"r_share",@"分享"],@[@"r_font",@"字体大小"],@[@"r_report",@"举报"]]];
}
- (void)setArr_text:(NSArray *)arr_text {
    _arr_text = arr_text;
    self.tbv_main.height = _arr_text.count * ROW_HEIGHT;
    self.height = _arr_text.count * ROW_HEIGHT;
    [self.tbv_main reloadData];
}
- (void)setArr_imageName:(NSArray *)arr_imageName {
    _arr_imageName = arr_imageName;
    [self.tbv_main reloadData];
}
- (void)setSeparatorColor:(UIColor *)separatorColor {
    _separatorColor = separatorColor;
    [self.tbv_main reloadData];
}
- (void)setSelectedStr:(NSString *)selectedStr {
    _selectedStr = selectedStr;
    [self.tbv_main reloadData];
}
#pragma mark - Table view data source
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return self.arr_text.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"menuCells"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"menuCells"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        UIView *line = UIView.new;
        line.tag = 10;
        [cell.contentView addSubview:line];
        line.frame = CGRectMake(0, ROW_HEIGHT - 1, cell.contentView.frame.size.width, 1);
    }
    UIView *line = [cell.contentView viewWithTag:10];
    line.backgroundColor = _separatorColor;
    
    cell.imageView.image = [UIImage imageNamed:self.arr_imageName[indexPath.row]];
    
    cell.textLabel.text = self.arr_text[indexPath.row];
    if (self.arr_imageName.count == 0) {
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
    }
    cell.textLabel.font = GET_SYSTEM_FONT(TEXT_FONT_42);
    
    if ([_selectedStr isEqualToString:self.arr_text[indexPath.row]]) {
        cell.selected = YES;
    }
    if (cell.selected)
        cell.textLabel.textColor = GET_HEX_COLOR(CELL_LABLE_BORDER_RED);
    else
        cell.textLabel.textColor = GET_HEX_COLOR(TEXT_DEEP_GRAY);

    return cell;
}

#pragma mark - Table view delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return ROW_HEIGHT;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.clickBlock) {
        self.clickBlock(indexPath.row,self);
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
